﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using BonsaiScrum.Core.Persistance;
using BonsaiScrum.Bus;

namespace BonsaiScrum.Mvc.Services
{
    public class AccountMembershipService : IMembershipService
    {
        private IUserReportingRepository _userReportingRepository;
        private ICommandBus _commandBus;
        
        public AccountMembershipService(IUserReportingRepository userReportingRepository, ICommandBus commandBus)
        {
            _userReportingRepository = userReportingRepository;
            _commandBus = commandBus;
        }

        public int MinPasswordLength { get { return 6; } }
       

        public bool ValidateUser(string userName, string password)
        {
            if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName");
            if (String.IsNullOrEmpty(password)) throw new ArgumentException("Value cannot be null or empty.", "password");

            var user = _userReportingRepository.GetUserWithUserName(userName);

            if (user == null) return false;

            return user.Password.Equals(password);
        }

        public bool ChangePassword(string userName, string oldPassword, string newPassword)
        {
            if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName");
            if (String.IsNullOrEmpty(oldPassword)) throw new ArgumentException("Value cannot be null or empty.", "oldPassword");
            if (String.IsNullOrEmpty(newPassword)) throw new ArgumentException("Value cannot be null or empty.", "newPassword");

            var currentUser = _userReportingRepository.GetUserWithUserName(userName);
            throw new NotImplementedException();
        }
    }
}
